package tech.dx.springdb.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.dx.springdb.entity.ClassRecords;
import tech.dx.springdb.service.ClassRecordsService;

import java.util.Optional;

/**
 * @ClassName ClassRecordsController
 * @Description TODO
 * @Author daoxuan
 * @Date 2019/4/1 17:26
 * @Version 1.0
 */
@RestController
@RequestMapping("classrecordsc")
@Api(value = "课程记录API",tags = {"学生课程记录的REST"})
public class ClassRecordsController {
    @Autowired
    private ClassRecordsService classRecordsService;

    @GetMapping("/{id}")
    public ClassRecords get(@PathVariable long id){
        Optional<ClassRecords> byId = classRecordsService.getById(id);
        if (byId.isPresent()){
            return byId.get();
        }else {
            return null;
        }
    }

    @PostMapping
    @ApiOperation(value = "增加课程记录")
    public ClassRecords add(@RequestBody  ClassRecords classRecords){
        return classRecordsService.add(classRecords);
    }

    @PutMapping
    public ClassRecords update(ClassRecords classRecords){
        return classRecordsService.update(classRecords);
    }

    @DeleteMapping("/{id}")
    public void del(@PathVariable long id){
        classRecordsService.del(id);
    }
}
